package com.shxzz.shortlink.admin.config;

import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author shxzz
 * @create 2023-12-11-21:22
 * @description 布隆过滤器配置
 */
@Configuration
public class RBloomFilterConfiguration {

    /**
     * 用户名布隆过滤器，防止检查用户名存在时，查询数据库
     */
    @Bean
    public RBloomFilter<String> userRegisterCachePenetrationRBloomFilter(RedissonClient redissonClient) {
        RBloomFilter<String> userRegisterCachePenetration = redissonClient
                .getBloomFilter("userRegisterCachePenetration");

        userRegisterCachePenetration.tryInit(100000000L,0.001);

        return userRegisterCachePenetration;
    }
}
